home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / gfx / x11 / x3270_3_2_16.lha / amiga_src / CmeLine.c < prev    next >
C/C++ Source or Header  |  2001-06-24  |  10KB  |  309 lines

  1. /* (from) $XConsortium: SmeLine.c,v 1.13 91/07/23 12:23:21 rws Exp $ */
  2.  
  3. /*
  4.  * Modifications Copyright 1995, 1999 by Paul Mattes.
  5.  *  Permission to use, copy, modify, and distribute this software and its
  6.  *  documentation for any purpose and without fee is hereby granted,
  7.  *  provided that the above copyright notice appear in all copies and that
  8.  *  both that copyright notice and this permission notice appear in
  9.  *  supporting documentation.
  10.  *
  11.  * Copyright 1989 Massachusetts Institute of Technology
  12.  *
  13.  * Permission to use, copy, modify, distribute, and sell this software and its
  14.  * documentation for any purpose is hereby granted without fee, provided that
  15.  * the above copyright notice appear in all copies and that both that
  16.  * copyright notice and this permission notice appear in supporting
  17.  * documentation, and that the name of M.I.T. not be used in advertising or
  18.  * publicity pertaining to distribution of the software without specific,
  19.  * written prior permission.  M.I.T. makes no representations about the
  20.  * suitability of this software for any purpose.  It is provided "as is"
  21.  * without express or implied warranty.
  22.  *
  23.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  24.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  25.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  26.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  27.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  28.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  29.  *
  30.  * Author:  Chris D. Peterson, MIT X Consortium
  31.  */
  32.  
  33. /*
  34.  * Cme.c - Source code for the generic menu entry
  35.  * (from) Sme.c - Source code for the generic menu entry
  36.  *
  37.  * Date:    September 26, 1989
  38.  *
  39.  * By:      Chris D. Peterson
  40.  *          MIT X Consortium 
  41.  *          kit@expo.lcs.mit.edu
  42.  */
  43.  
  44. #include "globals.h"
  45. #if defined(X3270_MENUS) /*[*/
  46.  
  47. #include <stdio.h>
  48. #include <X11/IntrinsicP.h>
  49. #include <X11/StringDefs.h>
  50.  
  51. #include <X11/Xaw/XawInit.h>
  52. #include "CmeLineP.h"
  53. #include <X11/Xaw/Cardinals.h>
  54.  
  55. #define offset(field) XtOffsetOf(CmeLineRec, cme_line.field)
  56. static XtResource resources[] = {
  57.   {XtNlineWidth, XtCLineWidth, XtRDimension, sizeof(Dimension),
  58.      offset(line_width), XtRImmediate, (XtPointer) 1},
  59.   {XtNstipple, XtCStipple, XtRBitmap, sizeof(Pixmap),
  60.      offset(stipple), XtRImmediate, (XtPointer) XtUnspecifiedPixmap},
  61.   {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
  62.      offset(foreground), XtRString, XtDefaultForeground},
  63. };   
  64. #undef offset
  65.  
  66. /*
  67.  * Function definitions. 
  68.  */
  69.  
  70. static void Redisplay(Widget, XEvent *, Region);
  71. static void Initialize(Widget, Widget, ArgList, Cardinal *);
  72. static void DestroyGC(Widget);
  73. static void CreateGC(Widget);
  74. static Boolean SetValues(Widget, Widget, Widget, ArgList, Cardinal *);
  75. static XtGeometryResult QueryGeometry(Widget, XtWidgetGeometry *,
  76.     XtWidgetGeometry *);
  77.  
  78.  
  79. #define SUPERCLASS (&cmeClassRec)
  80.  
  81. void relay_func4(void)
  82. {
  83. XawInitializeWidgetSet();
  84. }
  85.  
  86. CmeLineClassRec cmeLineClassRec = {
  87.   {
  88.     /* superclass         */    (WidgetClass) SUPERCLASS,
  89.     /* class_name         */    "CmeLine",
  90.     /* size               */    sizeof(CmeLineRec),
  91.     /* class_initialize   */    relay_func4,
  92.     /* class_part_initialize*/    NULL,
  93.     /* Class init'ed      */    FALSE,
  94.     /* initialize         */    Initialize,
  95.     /* initialize_hook    */    NULL,
  96.     /* realize            */    NULL,
  97.     /* actions            */    NULL,
  98.     /* num_actions        */    ZERO,
  99.     /* resources          */    resources,
  100.     /* resource_count     */    XtNumber(resources),
  101.     /* xrm_class          */    NULLQUARK,
  102.     /* compress_motion    */    FALSE, 
  103.     /* compress_exposure  */    FALSE,
  104.     /* compress_enterleave*/     FALSE,
  105.     /* visible_interest   */    FALSE,
  106.     /* destroy            */    DestroyGC,
  107.     /* resize             */    NULL,
  108.     /* expose             */    Redisplay,
  109.     /* set_values         */    SetValues,
  110.     /* set_values_hook    */    NULL,
  111.     /* set_values_almost  */    0,  
  112.     /* get_values_hook    */    NULL,            
  113.     /* accept_focus       */    NULL,
  114.     /* intrinsics version */    XtVersion,
  115.     /* callback offsets   */    NULL,
  116.     /* tm_table          */    NULL,
  117.     /* query_geometry      */    QueryGeometry,
  118.     /* display_accelerator*/    NULL,
  119.     /* extension      */    NULL
  120.   },{
  121.     /* Menu Entry Fields */
  122.       
  123. #ifndef AMIGA
  124.     /* highlight */             XtInheritHighlight,
  125.     /* unhighlight */           XtInheritUnhighlight,
  126.     /* notify */        XtInheritNotify,        
  127. #else
  128. NULL,NULL,NULL,
  129. #endif
  130.     /* extension */             NULL                
  131.   },{
  132.     /* Line Menu Entry Fields */
  133.     /* extension */             NULL                
  134.   }
  135. };
  136.  
  137. WidgetClass cmeLineObjectClass = (WidgetClass) &cmeLineClassRec;
  138.  
  139. #ifdef AMIGA
  140. void AMIGA_INIT_CMELINE(void)
  141.  {
  142.  cmeLineClassRec.set_values_almost=XtInheritSetValuesAlmost;
  143.  cmeLineClassRec.highlight=SUPERCLASS->highlight;
  144.  cmeLineClassRec.unhighlight=SUPERCLASS->unhighlight;
  145.  cmeLineClassRec.notify=SUPERCLASS->notify;
  146.  
  147.  }
  148. #endif
  149.  
  150. /************************************************************
  151.  *
  152.  * Semi-Public Functions.
  153.  *
  154.  ************************************************************/
  155.  
  156. /*      Function Name: Initialize
  157.  *      Description: Initializes the complex menu widget
  158.  *      Arguments: request - the widget requested by the argument list.
  159.  *                 new     - the new widget with both resource and non
  160.  *                           resource values.
  161.  *      Returns: none.
  162.  */
  163.  
  164. static void
  165. Initialize(Widget request unused, Widget new, ArgList args unused,
  166.     Cardinal *num_args unused)
  167. {
  168.     CmeLineObject entry = (CmeLineObject) new;
  169.  
  170.     if (entry->rectangle.height == 0)
  171.     entry->rectangle.height = entry->cme_line.line_width;
  172.  
  173.     CreateGC(new);
  174. }
  175.  
  176. /*    Function Name: CreateGC
  177.  *    Description: Creates the GC for the line entry widget.
  178.  *    Arguments: w - the Line entry widget.
  179.  *    Returns: none
  180.  *
  181.  *      We can only share the GC if there is no stipple, because
  182.  *      we need to change the stipple origin when drawing.
  183.  */
  184.  
  185. static void
  186. CreateGC(Widget w)
  187. {
  188.     CmeLineObject entry = (CmeLineObject) w;
  189.     XGCValues values;
  190.     XtGCMask mask = GCForeground | GCGraphicsExposures | GCLineWidth ;
  191.     
  192.     values.foreground = entry->cme_line.foreground;
  193.     values.graphics_exposures = FALSE;
  194.     values.line_width = entry->cme_line.line_width;
  195.     
  196.     if (entry->cme_line.stipple != XtUnspecifiedPixmap) {
  197.     values.stipple = entry->cme_line.stipple;
  198.     values.fill_style = FillStippled; 
  199.     mask |= GCStipple | GCFillStyle;
  200.     
  201.     entry->cme_line.gc = XCreateGC(XtDisplayOfObject(w), 
  202.                       RootWindowOfScreen(XtScreenOfObject(w)),
  203.                       mask, &values);
  204.     }
  205.     else
  206.     entry->cme_line.gc = XtGetGC(w, mask, &values);
  207. }
  208.  
  209. /*    Function Name: DestroyGC
  210.  *    Description: Destroys the GC when we are done with it.
  211.  *    Arguments: w - the Line entry widget.
  212.  *    Returns: none
  213.  */
  214.  
  215. static void
  216. DestroyGC(Widget w)
  217. {
  218.     CmeLineObject entry = (CmeLineObject) w;
  219.  
  220.     if (entry->cme_line.stipple != XtUnspecifiedPixmap) 
  221.     XFreeGC(XtDisplayOfObject(w), entry->cme_line.gc);
  222.     else
  223.     XtReleaseGC(w, entry->cme_line.gc);
  224. }
  225.  
  226. /*    Function Name: Redisplay
  227.  *    Description: Paints the Line
  228.  *    Arguments: w - the menu entry.
  229.  *                 event, region - NOT USED.
  230.  *    Returns: none
  231.  */
  232.  
  233. static void
  234. Redisplay(Widget w, XEvent *event unused, Region region unused)
  235. {
  236.     CmeLineObject entry = (CmeLineObject) w;
  237.     int y = entry->rectangle.y + 
  238.         (int)(entry->rectangle.height - entry->cme_line.line_width) / 2;
  239.  
  240.     if (entry->cme_line.stipple != XtUnspecifiedPixmap) 
  241.     XSetTSOrigin(XtDisplayOfObject(w), entry->cme_line.gc, 0, y);
  242.  
  243.     XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w),
  244.            entry->cme_line.gc, 
  245.            0, y, (unsigned int) entry->rectangle.width, 
  246.            (unsigned int) entry->cme_line.line_width );
  247. }
  248.  
  249. /*      Function Name: SetValues
  250.  *      Description: Relayout the menu when one of the resources is changed.
  251.  *      Arguments: current - current state of the widget.
  252.  *                 request - what was requested.
  253.  *                 new - what the widget will become.
  254.  *      Returns: none
  255.  */
  256.  
  257. static Boolean
  258. SetValues(Widget current, Widget request unused, Widget new,
  259.     ArgList args unused, Cardinal *num_args unused)
  260. {
  261.     CmeLineObject entry = (CmeLineObject) new;
  262.     CmeLineObject old_entry = (CmeLineObject) current;
  263.   
  264.     if ( (entry->cme_line.line_width != old_entry->cme_line.line_width) &&
  265.      (entry->cme_line.stipple != old_entry->cme_line.stipple) ) {
  266.     DestroyGC(current);
  267.     CreateGC(new);
  268.     return(TRUE);
  269.     }
  270.     return(FALSE);
  271. }
  272.  
  273. /*    Function Name: QueryGeometry.
  274.  *    Description: Returns the preferred geometry for this widget.
  275.  *    Arguments: w - the menu entry object.
  276.  *                 itended, return - the intended and return geometry info.
  277.  *    Returns: A Geometry Result.
  278.  *
  279.  * See the Intrinsics manual for details on what this function is for.
  280.  * 
  281.  * I just return the height and a width of 1.
  282.  */
  283.  
  284. static XtGeometryResult
  285. QueryGeometry(Widget w, XtWidgetGeometry *intended,
  286.     XtWidgetGeometry *return_val)
  287. {
  288.     CmeObject entry = (CmeObject) w;
  289.     Dimension width;
  290.     XtGeometryResult ret_val = XtGeometryYes;
  291.     XtGeometryMask mode = intended->request_mode;
  292.  
  293.     width = 1;            /* we can be really small. */
  294.  
  295.     if ( ((mode & CWWidth) && (intended->width != width)) ||
  296.      !(mode & CWWidth) ) {
  297.     return_val->request_mode |= CWWidth;
  298.     return_val->width = width;
  299.     mode = return_val->request_mode;
  300.     
  301.     if ( (mode & CWWidth) && (width == entry->rectangle.width) )
  302.         return(XtGeometryNo);
  303.     return(XtGeometryAlmost);
  304.     }
  305.     return(ret_val);
  306. }
  307.  
  308. #endif /*]*/
  309.